$(function() { //页面上的按钮，右键菜单等 事件绑定操作
	//$('[data-toggle="popover"]').popover();

	let $btnCopy = document.querySelector("#btn_copy"); //上传识别按钮
	$btnCopy.onclick = copyToClipboard;

	//画出 boxes函数
	document.querySelector('#drawRect').onclick = function() {
		if (window.g_data) // 这里有问题  
			showBoxesInCanvas(); //画出boxes
		else
			console.log('no g_data');
	}
	///*
	//长按/单击的时间
	// if (isMobileDevice() == true) {
	$('#showBox').on({
		touchstart: function(e) {
			console.log('touchstart: X=', e.originalEvent.touches[0].clientX, '\tY=', e
				.originalEvent.touches[0].clientY);
			tid = setTimeout(c, 70, e); //(e); //触发长按事件
			//e.preventDefault();
		},
		touchmove: function(e) {
			clearTimeout(tid);
			tid = 0;
		},
		touchend: function(e) {
			clearTimeout(tid);
			return false;
		}
	});
	// } else {
	//*/

	document.querySelector("#showBox").addEventListener('mousedown', doShowDiv); //触发长按事件
	// }
	//*/
	//设置弹出菜单的选项的点击事件
	$('#menu a').each(function(index, dom) {
		var msg = ["确定修改为发芽种子?", "确定修改为单叶种子?", "确定修改为不确定种子?", "确定修改为不是种子?", "不做修改，退出菜单！"];

		$(this).on('click', function() {
			if (index == 4) {
				setTimeout(removeCurrentDiv, 1200); //必须等一会再去除
				return; //直接退出	
			}

			bootbox.confirm({
				size: "small",
				message: msg[index],
				title: "修改结果",
				callback: function(result) {
					console.log(index + ":" + result);
					if (result == true) {
						try {
							var div = window.saveDiv;

							let label = div.getAttribute('my_label');
							let ii = div.getAttribute('my_index');

							setSeedLabel(index, ii); //设置种子检测结果变化
						} catch (e) {
							console.log(e);
						}
					}
					removeCurrentDiv();
				}
			});
		});
	});

	$('#health, #oneleaf').on('change', function() { //触发种子数量的 更新
		let arr = getInputDataArray();
		let seeds = arr[0] + arr[1];
		$('#seeds').val(seeds).trigger('change');
	})

	document.querySelector("#labelNumber").onclick = function() {
		if (!window.g_data)
			return;

		if (this.checked == true) {
			const $canvas = document.querySelector("#showBox");
			let ctx = $canvas.getContext("2d");
			labelSeedNumbers(ctx);
		} else {
			showBoxesInCanvas();
		}
	}
	document.querySelector("#labelShow").onclick = function() {
		if (!window.g_data)
			return;

		if (this.checked == true) {
			showBoxesInCanvas();
		} else {
			removeBoxes();
		}
	}
})
